package run.newbug.pro03.security.interceptor;

import org.assertj.core.groups.Tuple;
import org.springframework.web.servlet.HandlerInterceptor;
import run.newbug.pro03.util.JwtUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TokenInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("You are fucking damned");
        String authentication = request.getParameter("authentication");
        if(authentication == null || "".equals(authentication)){
//            System.out.println("illegal authentication");
            throw new RuntimeException("illegal authentication");
        }
        Boolean flag = JwtUtils.isTokenExpired(authentication);
        if(flag){
            throw new RuntimeException("illegal flag");
        }
        return true;
    }
}
